#!/usr/bin/env bash
#function: install containerd
#parmeter:
#author:
#version: 1.0
#Test: ubuntu24.2


echo "***this tool require wget***"


export containerdver="2.1.1"
export runcver="1.2.6"
export cniver="1.7.1"
export nerdctlver="2.1.2"

function getbasepackage()
{
  # from github to get 
  # containerd  使用 static 版本
   
  
  
  #wget -c  https://github.com/containerd/containerd/releases/download/v2.1.1/containerd-static-2.1.1-linux-amd64.tar.gz
  #wget -c  "https://github.com/containerd/containerd/releases/download/v$containerdver/containerd-static-$containerdver-linux-amd64.tar.gz"
  #echo "https://github.com/containerd/containerd/releases/download/v$containerdver/containerd-static-$containerdver-linux-amd64.tar.gz"
  wget -c  "https://github.com/containerd/containerd/releases/download/v$containerdver/containerd-static-$containerdver-linux-amd64.tar.gz"
  
  #https://github.com/opencontainers/runc/releases/download/v1.2.6/runc.amd64  
  
  wget -c https://github.com/opencontainers/runc/releases/download/v$runcver/runc.amd64  

  #https://github.com/containernetworking/plugins/releases/download/v1.7.1/cni-plugins-linux-amd64-v1.7.1.tgz
  wget -c https://github.com/containernetworking/plugins/releases/download/v$cniver/cni-plugins-linux-amd64-v$cniver.tgz
  

}





function installcontainerd()
{

      tar Cxzvf /usr/local  containerd-static-$containerdver-linux-amd64.tar.gz
      cp containerd.service /lib/systemd/system/

      systemctl daemon-reload
      systemctl enable  containerd
      systemctl start  containerd
      systemctl  status containerd

}


function installrunc()
{

    install -m 755 runc.amd64 /usr/local/sbin/runc

}



function installcni()
{

    mkdir -p /opt/cni/bin
    tar Cxzvf /opt/cni/bin cni-plugins-linux-amd64-v$cniver.tgz

}







function installnerdctl()
{

#https://github.com/containerd/nerdctl/releases/download/v2.1.2/nerdctl-2.1.2-linux-amd64.tar.gz

wget -c https://github.com/containerd/nerdctl/releases/download/v$nerdctlver/nerdctl-$nerdctlver-linux-amd64.tar.gz

tar -zxvf nerdctl-$nerdctlver-linux-amd64.tar.gz

cp nerdctl /usr/local/sbin/


}






while :
do
cat <</
    1)获取安装包
    2)安装containerd
    3)安装runc
    4)安装cni
    5)安装nerdctl
/
echo  "请选择对用选项"
     read choose
     case $choose in
     1)
      getbasepackage;;
     2)
      installcontainerd;;
     3)
      installrunc;;
     4)
      installcni;;        
     5)
      installnerdctl;;             
     esac

done
